package o;

import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnPreDrawListener;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.transition.AutoTransition;
import androidx.transition.Transition;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;

public class nr {
    static ArrayList<ViewGroup> ˎ = new ArrayList();
    private static ThreadLocal<WeakReference<ds<ViewGroup, ArrayList<Transition>>>> ˏ = new ThreadLocal();
    private static Transition ॱ = new AutoTransition();
    private ds<no, Transition> ˊ = new ds();
    private ds<no, ds<no, Transition>> ˋ = new ds();

    static class c implements OnPreDrawListener, OnAttachStateChangeListener {
        ViewGroup ˋ;
        Transition ˏ;

        c(Transition transition, ViewGroup viewGroup) {
            this.ˏ = transition;
            this.ˋ = viewGroup;
        }

        private void ˎ() {
            this.ˋ.getViewTreeObserver().removeOnPreDrawListener(this);
            this.ˋ.removeOnAttachStateChangeListener(this);
        }

        public void onViewAttachedToWindow(View view) {
        }

        public void onViewDetachedFromWindow(View view) {
            ˎ();
            nr.ˎ.remove(this.ˋ);
            ArrayList arrayList = (ArrayList) nr.ˏ().get(this.ˋ);
            if (arrayList != null && arrayList.size() > 0) {
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    ((Transition) it.next()).ᐝ(this.ˋ);
                }
            }
            this.ˏ.ॱ(true);
        }

        public boolean onPreDraw() {
            ˎ();
            if (nr.ˎ.remove(this.ˋ)) {
                ArrayList arrayList;
                final ds ˏ = nr.ˏ();
                ArrayList arrayList2 = (ArrayList) ˏ.get(this.ˋ);
                if (arrayList2 == null) {
                    arrayList2 = new ArrayList();
                    ˏ.put(this.ˋ, arrayList2);
                    arrayList = arrayList2;
                    arrayList2 = null;
                } else if (arrayList2.size() > 0) {
                    ArrayList arrayList3 = new ArrayList(arrayList2);
                    arrayList = arrayList2;
                    arrayList2 = arrayList3;
                } else {
                    arrayList = arrayList2;
                    arrayList2 = null;
                }
                arrayList.add(this.ˏ);
                this.ˏ.ˊ(new nq(this) {
                    final /* synthetic */ c ˏ;

                    public void ˋ(@NonNull Transition transition) {
                        ((ArrayList) ˏ.get(this.ˏ.ˋ)).remove(transition);
                    }
                });
                this.ˏ.ˊ(this.ˋ, false);
                if (arrayList2 != null) {
                    Iterator it = arrayList2.iterator();
                    while (it.hasNext()) {
                        ((Transition) it.next()).ᐝ(this.ˋ);
                    }
                }
                this.ˏ.ˋ(this.ˋ);
            }
            return true;
        }
    }

    static ds<ViewGroup, ArrayList<Transition>> ˏ() {
        ds<ViewGroup, ArrayList<Transition>> dsVar;
        WeakReference weakReference = (WeakReference) ˏ.get();
        if (weakReference != null) {
            dsVar = (ds) weakReference.get();
            if (dsVar != null) {
                return dsVar;
            }
        }
        dsVar = new ds();
        ˏ.set(new WeakReference(dsVar));
        return dsVar;
    }

    private static void ˎ(ViewGroup viewGroup, Transition transition) {
        if (transition != null && viewGroup != null) {
            Object cVar = new c(transition, viewGroup);
            viewGroup.addOnAttachStateChangeListener(cVar);
            viewGroup.getViewTreeObserver().addOnPreDrawListener(cVar);
        }
    }

    private static void ˋ(ViewGroup viewGroup, Transition transition) {
        ArrayList arrayList = (ArrayList) ˏ().get(viewGroup);
        if (arrayList != null && arrayList.size() > 0) {
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                ((Transition) it.next()).ˋ((View) viewGroup);
            }
        }
        if (transition != null) {
            transition.ˊ(viewGroup, true);
        }
        no ˊ = no.ˊ(viewGroup);
        if (ˊ != null) {
            ˊ.ॱ();
        }
    }

    public static void ˊ(@NonNull ViewGroup viewGroup, @Nullable Transition transition) {
        if (!ˎ.contains(viewGroup) && ViewCompat.ˊᐝ(viewGroup)) {
            ˎ.add(viewGroup);
            if (transition == null) {
                transition = ॱ;
            }
            Transition ॱˋ = transition.ॱˋ();
            ˋ(viewGroup, ॱˋ);
            no.ˊ(viewGroup, null);
            ˎ(viewGroup, ॱˋ);
        }
    }
}
